﻿using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Service;
using Omu.AwesomeDemo.Infra.Builder;
using Omu.AwesomeDemo.Infra.Dto;
using Omu.AwesomeDemo.Core.Model;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class HobbyController : Cruder<Hobby, HobbyInput>
    {
        public HobbyController(ICrudService<Hobby> s, IBuilder<Hobby, HobbyInput> v)
            : base(s, v)
        {
        }
     
        public ActionResult Search(string name, int page = 1, int ps = 5)
        {
            var src = s.GetAll().Where(o => o.Name != null && o.Name.ToLower().Contains(name.ToLower()));
            var rows = this.RenderView("rows", src.Skip((page - 1) * ps).Take(ps));
           
            return Json(new {rows, more = src.Count() > page * ps });
        }
    }
}